<{assign var=page_title value=$page_title2|default:'管理用户' }>
<{ include file="FASHION/page_header.phtml" }>

<{php}>
$this->assign('hasRole', UserPrivHelper::check('role'));
<{/php}>

<table border="0" id="list" class="list"><tbody>
<tr>
	<th>UID</th>
	<th>用户名</th>
	<th>昵称</th>
	<th>邮箱</th>
	<th>部门</th>
	<th width="100">角色</th>
	<th>状态</th>
	<th width="100">添加时间</th>
	<th>操作</th>
</tr>

<{foreach item=u from=$list }>
<tr user_id="<{$u.id}>">
	<td><{$u.id}></td>
	<td><{$u.account}></td>
	<td><{$u.name}></td>
	<td><{$u.email}></td>
	<td dept_id="<{$u.dept_id}>"><{$u.dept_name}></td>
	<td class="nobr">
        <{php}>
            $u = $this->get_template_vars('u');
            $this->assign('_roles', RoleHelper::getByUser($u['id']));
        <{/php}>
        <{foreach item=_rname key=_rid from=$_roles}>
            <{if $hasRole}>
                <div><a href='role-modify/id/<{$_rid}>'><{$_rname}></a></div>
            <{else}>
                <div><{$_rname}></div>
            <{/if}>
        <{/foreach}>
	</td>
	<td><div class="disa_<{$u.is_disa}>" is_disa="<{$u.is_disa}>" user_id="<{$u.id}>"></div></td>
	<td><{$u.addtime|date_format:"%Y/%m/%d"}></td>
	<td>
        <a href="user-role/id/<{$u.id}>">权限</a>
		<a href="javascript:;" onclick="modify('<{$u.id}>')">修改</a>
	</td>
</tr>
<{/foreach}>
</tbody></table>

<br/>
<input type="button" value="增加用户" onclick="add()" />


<script>

function add()
{
	$.get('<{url a='user-nature'}>', function(jsn){
		_show_dialog(1, jsn);
		return ;
	});
}

function modify(user_id)
{
	$.get('<{url a='user-nature/user_id/USER_ID'}>'.replace('USER_ID',user_id), function(jsn){
		_show_dialog(0, jsn);
		return ;
	});
}

function _show_dialog(type, jsn){
	if(!ajax_ok(jsn)) return ;
	show_dialog({
		title	: type ? '添加用户' : '修改用户',
		content	: jsn.message,
                height: 500,
		ajaxform : function(jsn){
			if(jsn.method=='update'){
				$('tr[user_id='+jsn.user_id+']').replaceWith(jsn.html);
			}
			else{
				$('#list > tbody').append(jsn.html);
			}
		}
	});
}

/*
function del(user_id)
{
	if(confirm('确认删除?'))
	{
		$.get('<{url a='user-delete/user_id/USER_ID')}>'.replace('USER_ID',user_id), function(jsn){
			if(jsn.level=='notice') {
				$("#sortable li[user_id="+user_id+"]").remove();
			}
			alert(jsn.message);
		});
	}
}
*/

function switch_disa(){
	$.get('<{ url a='user-disa/user_id/USER_ID/disa/DISA' }>'
		.replace('USER_ID', $(this).attr('user_id'))
		.replace('DISA', $(this).attr('is_disa')), function(jsn){
			$("div[is_disa][user_id="+jsn.user_id+"]")
				.attr('class', 'disa_'+jsn.disa)
				.attr('is_disa', jsn.disa);
		});
}

$('div[is_disa]').click(switch_disa);

</script>

<{include file="FASHION/page_footer.phtml"}>
